name: Text

on:
 push:
  paths:
  - '.github/workflows/text.yml'
  - 'Fallout2/Fallout1in2/**/*.[Mm][Ss][Gg]'
 pull_request:
  paths:
  - '.github/workflows/text.yml'
  - 'Fallout2/Fallout1in2/**/*.[Mm][Ss][Gg]'

defaults:
 run:
  shell: bash

jobs:
 ScanMsg:
  if:      github.actor != 'antalaskaya' && github.ref == 'refs/heads/master'
  runs-on: windows-latest
  steps:

  - name: Clone
    uses: actions/checkout@v4

  - name: ScanMsg
    uses: wipe2238/ScanMsg@master
    with:
     workdir: Fallout2/Fallout1in2/mods/

 Translations:
  if:      github.actor != 'antalaskaya' && github.ref == 'refs/heads/master'
  needs:   ScanMsg
  runs-on: ubuntu-latest
  steps:

  - name: Install
    run:  sudo apt update && sudo apt install -y gettext && hash -r

  - name: Clone
    uses: actions/checkout@v4
    with:
     ref:   translations
     token: ${{ secrets.ANTALASKAYA_TOKEN }}

  - name: msg2tra
    run:  |
          :
          if [[ -f "msg2tra.sh" ]]; then
             echo ::group::msg2tra
             ./msg2tra.sh
             echo ::endgroup::
             if [[ -n $(git status --short --untracked-files=all Translations/po/) ]]; then
                git add Translations/po/
                echo "Synchronize with master branch" >> .git/gha.commit
             fi
          fi

  - name: Validation
    run:  |
          :
          echo ::group::git status
          git status 2>&1
          echo ::endgroup::

          if [[ -f .git/gha.commit ]]; then
             cat .git/gha.commit
             echo GHA_COMMIT=true >> $GITHUB_ENV
          fi

  - name: Push
    if:   env.GHA_COMMIT == 'true'
    run:  |
          :
          echo ::group::git commit
          git config --global user.name  "${{ secrets.ANTALASKAYA_NAME }}"
          git config --global user.email "${{ secrets.ANTALASKAYA_EMAIL }}"
          git commit --file=".git/gha.commit" 2>&1
          rm -f .git/gha.commit
          echo ::endgroup::

          echo ::group::git log
          git log -p -n 1 2>&1
          echo ::endgroup::

          echo ::group::git push
          #git push 2>&1
          echo ::endgroup::
    continue-on-error: true
